package com.eric.utils.page;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * 解析html页面，并返回数据结果
 * @author Eric
 *
 */
public class AnalyticParser {

	public static int elementDepth (Element element) {
		return element.parents().size();
	}
	
	public static int maxElementDepth (Elements elements) {
		int d = 0;
		for (Element e : elements) {
			int p = AnalyticParser.elementDepth(e);
			if (p > d)
				d = p;
		}
		return d;
	}
	
	public static float avgElementDepth(Elements elements) {
		int d = 0, count = 0;
		for (Element e : elements) {
			count++;
			d = d + AnalyticParser.elementDepth(e);
		}
		return (float) d / count;
	}
}
